package com.yc.supermarket.service.impl;

import com.yc.supermarket.entity.Sales;
import com.yc.supermarket.entity.ShoppingCart;
import com.yc.supermarket.entity.Transaction;
import com.yc.supermarket.mapper.TransactionMapper;
import com.yc.supermarket.service.ITransaction;
import com.yc.supermarket.util.MybatisUtil;
import org.apache.ibatis.session.SqlSession;

public class TransactionImpl implements ITransaction {

    private TransactionMapper mapper;
    @Override
    public int add(Transaction transaction) {
        System.out.println("this is weige");
        SqlSession session = MybatisUtil.getSession();
        mapper = session.getMapper(TransactionMapper.class);
        System.out.println("kazhulw");
        int i = mapper.add(transaction);
        int k = transaction.getTransactionId();
        System.out.println("asdfg::"+k);
        return i;
    }

    @Override
    public int addSales(Sales sales) {
        SqlSession session=MybatisUtil.getSession();
        mapper=session.getMapper(TransactionMapper.class);
        int j=mapper.addSales(sales);
        return j;
    }

    @Override
    public int updateCart(ShoppingCart shoppingCart) {
        SqlSession session=MybatisUtil.getSession();
        mapper=session.getMapper(TransactionMapper.class);
        int i = mapper.updateCart(shoppingCart);
        return i;
    }
}
